﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace QLKS
{
    public partial class PNP : Form
    {
        public Mysql qmysql = new Mysql();
        public static string bid;
        public PNP()
        {
            InitializeComponent();

        }

        public string LocChuoi(string strText)
        {
            return Regex.Replace(strText.Trim(), @"\W\s+", "");
        }
        
        private void PNP_Load(object sender, EventArgs e)
        {
            
            int RoomID = DMP.BTName;
            date_NV.Format = DateTimePickerFormat.Custom;
            date_NV.CustomFormat = "yyyy-MM-dd HH:mm:ss";
            date_NV.Value = DateTime.Now;
            if(Program.TENP!="")
                tx_phong.Text = Program.TENP;
            if (Program.IDKH != "")
                tx_IDKH.Text = Program.IDKH;
        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            int Error = 0;
            if (Error == 0 && (tx_IDKH.Text == ""))
            {
                MessageBox.Show("Không để trống thông tin trong các mục có dấu *", "Thông Báo");
                Error = 1;
            }
            // Get data to string;
           // MessageBox.Show(tmp_map);
            string tmp_map = this.qmysql.GetIDRoomByName(tx_phong.Text);
            string tmp_makh = tx_IDKH.Text;
            string tmp_manv = LocChuoi(f_Login.User[0]);
            string tmp_ngayvao = LocChuoi(date_NV.Value.ToString());
            string tmp_trangthai = "1";

            if (Error == 0)
            {
                string cmdTextIsnv = "INSERT INTO ht_phieunp(MaP,MaKH,Ngayvao,MaNV,Trangthai) VALUES(?MaP,?MaKH,?Ngayvao,?MaNV,?Trangthai)";
                Dictionary<string, string> Params_isnv = new Dictionary<string, string>();
                Params_isnv["MaP"] = tmp_map;
                Params_isnv["MaKH"] = tmp_makh;
                Params_isnv["Ngayvao"] = tmp_ngayvao;
                Params_isnv["MaNV"] = tmp_manv;
                Params_isnv["Trangthai"] = tmp_trangthai;
                this.qmysql.NonQueryMysqlCommand(cmdTextIsnv, Params_isnv);
                MessageBox.Show("Đã nhập phòng thành công.", "Thông Báo");
                //reload data
                //Getdata from database.

                // dataShow.DataSource = qmysql.GetData();
                DMP dmp = new DMP();
                dmp.MdiParent = this.ParentForm;
                dmp.Show();
                this.Close();
               
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            DMP dmp = new DMP();
            dmp.MdiParent = this.ParentForm;
            dmp.Show();
            this.Close();
        }

        private void btn_ChonKH_Click(object sender, EventArgs e)
        {
            NhapKH nhapkh = new NhapKH();
            nhapkh.MdiParent = this.ParentForm;
            nhapkh.Show();
            this.Close();
        }
    }
}
